package cn.ekuma.epos.datalogic.define.dao.shard;

import cn.ekuma.epos.db.table.shard.I_StateFollowTable;
import com.openbravo.bean.AppUser;
import com.openbravo.bean.shard.AbstractStateFollowObject;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class StateFollowDAOHelper {
	public static TableDefinition getTable(I_Session s,String tableName){
		return  new TableDefinition(tableName
	            ,new Field[]{
		                    new Field(I_StateFollowTable.ID, Datas.STRING, Formats.STRING),
		                    new Field(I_StateFollowTable.CALLTIME,Datas.TIMESTAMP, Formats.TIMESTAMP),
		                    new Field(I_StateFollowTable.USERID,Datas.STRING, Formats.STRING,AppUser.class),
		                    new Field(I_StateFollowTable.PRIORITY,Datas.INT, Formats.INT),
		                    new Field(I_StateFollowTable.STATE,Datas.STRING, Formats.STRING),
		                    new Field(I_StateFollowTable.NEXTTIME,Datas.TIMESTAMP, Formats.TIMESTAMP),
		                    new Field(I_StateFollowTable.RELATIONID,Datas.STRING, Formats.STRING),
		                    new Field(I_StateFollowTable.RELATIONMAN,Datas.STRING, Formats.STRING),
		                    new Field(I_StateFollowTable.MEMO,Datas.STRING, Formats.STRING)
		                }
	           , new int[] {0});
		 }

		public static void writeInsertValues(DataWrite dp, AbstractStateFollowObject obj,int start) throws BasicException {
			dp.setString(start,obj.getId());
			dp.setTimestamp(start+1,obj.getCallTime());
			dp.setString(start+2,obj.getUserId());
			dp.setInt(start+3,obj.getPriority());
			dp.setString(start+4,obj.getState());
			dp.setTimestamp(start+5,obj.getNextTime());
			dp.setString(start+6,obj.getRelationID());
			dp.setString(start+7,obj.getRelationMan());
			dp.setString(start+8,obj.getMemo());
	    }

	    public static void readValues(DataRead dr,AbstractStateFollowObject obj,int start) throws BasicException {
	    	obj.setId(dr.getString(start));
			obj.setCallTime(dr.getTimestamp(start+1));
			obj.setUserId(dr.getString(start+2));
			obj.setPriority(dr.getInt(start+3));
			obj.setState(dr.getString(start+4));
			obj.setNextTime(dr.getTimestamp(start+5));
			obj.setRelationID(dr.getString(start+6));
			obj.setRelationMan(dr.getString(start+7));
			obj.setMemo(dr.getString(start+8));
			obj.setStateObjectId(dr.getString(start+9));
	    }
}
